<!DOCTYPE html>
<html lang="en-us">
<head><head>
    <meta name="google-site-verification" content="9vIieCe-Qpd78QOmBl63rGtIVbhY6sYyuxX3j8XWBA4" />
    <meta name="baidu-site-verification" content="LRrmH41lz7" />
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <meta name="baidu-site-verification" content="HGLXRsUXC4" />

    
    <meta name="baidu-site-verification" content="code-ANZvlnN0Xr" />

    
    <meta name="description" content="apache RocketMQ 是阿里巴巴在2016年11月捐赠给了apache基金会并于2017年9月顺利毕业成为apache顶级项目">
    
    <meta name="keyword"  content="liangyuanpeng|LanLiang|OpenYurt|Knative|Pulsar|Prometheus|Halo||边缘计算kubernetes|Docker|CloudNative|Golang|Rust|Istio|微服务">
    <link rel="shortcut icon" href="img/logo.png">


    
    <meta property="og:image" content="https://res.cloudinary.com/lyp/image/upload/v1543506262/hugo/blog.github.io/apache-rocketMQ-introduction/7046d2bf0d97278682129887309cc1a6.jpg" />
    <meta name="twitter:image" content="https://res.cloudinary.com/lyp/image/upload/v1543506262/hugo/blog.github.io/apache-rocketMQ-introduction/7046d2bf0d97278682129887309cc1a6.jpg" />


    <title>Apache RocketMQ单机部署-liangyuanpeng的博客 | liangyuanpeng&#39;s Blog</title>

    <link rel="canonical" href="/post/deploy-apache-rocketmq/">

    <link rel="stylesheet" href="https://res.cloudinary.com/lyp/raw/upload/v1537369740/hugo/css/iDisqus.min.css"/>

    
    <link rel="stylesheet" href="https://res.cloudinary.com/lyp/raw/upload/v1537369744/hugo/css/bootstrap.min.css">

    
    <link rel="stylesheet" href="https://res.cloudinary.com/lyp/raw/upload/v1537369740/hugo/css/hux-blog.min.css">

    
    <link rel="stylesheet" href="https://res.cloudinary.com/lyp/raw/upload/v1537369740/hugo/css/syntax.css">

    
    <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    
    
    <script src="https://res.cloudinary.com/lyp/raw/upload/v1537369966/hugo/js/jquery.min.js"></script>

    
    <script src="https://res.cloudinary.com/lyp/raw/upload/v1537369966/hugo/js/bootstrap.min.js"></script>

    
    <script src="https://res.cloudinary.com/lyp/raw/upload/v1537369964/hugo/js/hux-blog.min.js"></script>

    
    <script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "f73bc0092aeb491d89984c0eb5a87ac2"}'></script>
</head>

</head>

<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">Hi,I`m lan</a>
        </div>

        
        
        <div id="huxblog_navbar">
            <div class="navbar-collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/">Home</a>
                    </li>
                    
                    <li>
                        <a href="categories/cloudnative">cloudnative</a>
                    </li>
                    
                    <li>
                        <a href="categories/devops">devops</a>
                    </li>
                    
                    <li>
                        <a href="categories/iot">iot</a>
                    </li>
                    
                    <li>
                        <a href="categories/kubernetes">kubernetes</a>
                    </li>
                    
                    <li>
                        <a href="categories/tech">tech</a>
                    </li>
                    

                    
		            <li>
                        <a href="search">SEARCH <img src="img/search.png" height="15" style="cursor: pointer;"></a>
		            </li>
                    
                </ul>
            </div>
        </div>
        
    </div>
    
</nav>
<script>
    
    
    
    var $body   = document.body;
    var $toggle = document.querySelector('.navbar-toggle');
    var $navbar = document.querySelector('#huxblog_navbar');
    var $collapse = document.querySelector('.navbar-collapse');

    $toggle.addEventListener('click', handleMagic)
    function handleMagic(e){
        if ($navbar.className.indexOf('in') > 0) {
        
            $navbar.className = " ";
            
            setTimeout(function(){
                
                if($navbar.className.indexOf('in') < 0) {
                    $collapse.style.height = "0px"
                }
            },400)
        }else{
        
            $collapse.style.height = "auto"
            $navbar.className += " in";
        }
    }
</script>




<style type="text/css">
    header.intro-header{
        background-image: url('https://res.cloudinary.com/lyp/image/upload/v1543506262/hugo/blog.github.io/apache-rocketMQ-introduction/7046d2bf0d97278682129887309cc1a6.jpg')
    }
</style>
<header class="intro-header" >
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <div class="tags">
                       
                       <a class="tag" href="/tags/mq" title="MQ">
                           MQ
                        </a>
                        
                       <a class="tag" href="/tags/apache" title="apache">
                           apache
                        </a>
                        
                       <a class="tag" href="/tags/rocketmq" title="RocketMQ">
                           RocketMQ
                        </a>
                        
                       <a class="tag" href="/tags/java" title="java">
                           java
                        </a>
                        
                       <a class="tag" href="/tags/middleware" title="Middleware">
                           Middleware
                        </a>
                        
                       <a class="tag" href="/tags/%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97" title="消息队列">
                           消息队列
                        </a>
                        
                       <a class="tag" href="/tags/%E6%9E%B6%E6%9E%84%E6%BC%94%E8%BF%9B" title="架构演进">
                           架构演进
                        </a>
                        
                    </div>
                    <h1>Apache RocketMQ单机部署</h1>
                    <h2 class="subheading"></h2>
                    <span  class="meta">Posted by 梁远鹏 on 2018-11-27
                        
                        <span id="busuanzi_container_page_pv">|<span id="busuanzi_value_page_pv"></span><span>
                            <span id="/post/deploy-apache-rocketmq/" class="leancloud_visitors meta_data_item" data-flag-title="">
    <span class="post-meta-item-icon">
      <span class="octicon octicon-eye"></span> 
    </span>
    <i class="fa fa-eye"></i>
    <span class="old-visitors-count" style="display: none;"></span>
    <span class="leancloud-visitors-count"></span>
</span>






                            阅读 </span></span>|<span class="post-date">共1367字</span>，阅读约<span class="more-meta"> 3 分钟</span>
                        
                    </span>
                </div>
            </div>
        </div>
    </div>
</header>




<article>
    <div class="container">
        <div class="row">

            
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                post-container">

		
                <header>
                <h2>TOC</h2>
                </header>
                <nav id="TableOfContents">
  <ul>
    <li><a href="#前言">前言</a></li>
    <li><a href="#下载程序包">下载程序包</a></li>
    <li><a href="#启动name-server">启动name server</a></li>
    <li><a href="#启动broker">启动Broker</a></li>
    <li><a href="#发送消息和接收消息">发送消息和接收消息</a></li>
    <li><a href="#关闭服务">关闭服务</a></li>
    <li><a href="#faq">FAQ</a>
      <ul>
        <li><a href="#怎么修改name-server和broker的启动内存">怎么修改name server和broker的启动内存?</a></li>
        <li><a href="#需要配置外网访问要怎么配置呢">需要配置外网访问要怎么配置呢？</a></li>
      </ul>
    </li>
    <li><a href="#配置文件">配置文件</a></li>
  </ul>
</nav>
		
		<h2 id="前言">前言</h2>
<p>这篇文章以4.3.0版本为标准进行讲述在linux下部署RocketMQ单机实例,在此之前需要已配置JAVA环境。</p>
<blockquote>
<p>apache RocketMQ 是阿里巴巴在2016年11月捐赠给了apache基金会并于2017年9月顺利毕业成为apache顶级项目。</p>
</blockquote>
<h2 id="下载程序包">下载程序包</h2>
<p>直接使用一般就<a href="https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.3.2/rocketmq-all-4.3.2-source-release.zip">下载</a>已经编译好的二进制文件就好了,下载好以后</p>
<p><!-- raw HTML omitted -->&gt; unzip rocketmq-all-4.3.0-bin-release.zip<br>
&gt; cd rocketmq-all-4.3.0-bin-release/<br>
<!-- raw HTML omitted --></p>
<h2 id="启动name-server">启动name server</h2>
<p><!-- raw HTML omitted -->&gt; nohup sh bin/mqnamesrv &amp; 
<!-- raw HTML omitted --></p>
<p>tail一下日志看看是否已经启动成功<br>
<!-- raw HTML omitted -->&gt; tail -f ~/logs/rocketmqlogs/namesrv.log<br>
The Name Server boot success&hellip; 
<!-- raw HTML omitted --></p>
<h2 id="启动broker">启动Broker</h2>
<p><!-- raw HTML omitted -->&gt; nohup sh bin/mqbroker -n localhost:9876 &amp; 
<!-- raw HTML omitted --></p>
<p>tail一下日志看看是否已经启动成功<br>
<!-- raw HTML omitted -->&gt; tail -f ~/logs/rocketmqlogs/broker.log<br>
The broker[%s, 172.30.30.233:10911] boot success&hellip;
<!-- raw HTML omitted --></p>
<h2 id="发送消息和接收消息">发送消息和接收消息</h2>
<p>为了简单测试下，在发送/接收消息之前我们需要设置<code>NAMESRV_ADDR</code>环境变量<br>
<!-- raw HTML omitted -->&gt; export NAMESRV_ADDR=localhost:9876<br>
<!-- raw HTML omitted --></p>
<p>发送消息，测试用例中的方式是使用for循环发送了1000条消息<br>
<!-- raw HTML omitted -->&gt; sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer<br>
SendResult [sendStatus=SEND_OK, msgId= &hellip;
<!-- raw HTML omitted --></p>
<p>接收消息<br>
<!-- raw HTML omitted -->&gt; sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer<br>
SendResult [sendStatus=SEND_OK, msgId= &hellip;
<!-- raw HTML omitted --></p>
<h2 id="关闭服务">关闭服务</h2>
<p><!-- raw HTML omitted -->&gt; sh bin/mqshutdown broker<br>
The mqbroker(36695) is running&hellip;<br>
Send shutdown request to mqbroker(36695) OK
<!-- raw HTML omitted --></p>
<p><!-- raw HTML omitted -->&gt; sh bin/mqshutdown namesrv<br>
The mqnamesrv(36664) is running&hellip;<br>
Send shutdown request to mqnamesrv(36664) OK
<!-- raw HTML omitted --></p>
<p>到此，我们已经完成了一个简单的部署以及消息的发送和接收,但是这只是在内网下进行的收发消息。</p>
<h2 id="faq">FAQ</h2>
<h3 id="怎么修改name-server和broker的启动内存">怎么修改name server和broker的启动内存?</h3>
<p>一开始按照官网的步骤来操作往往会直接启动不起来，提示内存不足，那是因为name server和broker默认的启动JVM内存是4G，而内存在不够的情况下自然就启动失败了。</p>
<p>这时候需要修改name server和broker的启动内存参数,<br>
broker的启动内存参数在<code>runbroker.sh</code>下修改,windows下则是<code>runbroker.cmd</code><br>
name server的启动内存参数是在<code>runserver.sh</code>下修改,windows下则是<code>runserver.cmd</code></p>
<h3 id="需要配置外网访问要怎么配置呢">需要配置外网访问要怎么配置呢？</h3>
<p>在网上见过很多同学在配置外网访问的时候出现问题，得到的提示大多是
<code>No Topic Route Info</code><br>
这种提示一般都是连接失败了，<br>
1.broker没有允许自动创建topic，且发送消息对应的topic不存在<br>
2.broker没有正确的连接到name server<br>
3.product没有正确的连接到name server</p>
<ul>
<li>对于情况1，在启动<code>broker</code>的时候添加<code>autoCreateTopicEnable=true</code>参数就好了。</li>
<li>情况2呢，有可能是name server不存在或者是端口冲突，具体可以看日志的报错原因。</li>
<li>情况3的话,一般是端口原因，如果在服务器上本地收发消息都正常但是到了用客户端sdk发消息的时候失败了可以首先查看一下端口本地ping服务器的9876端口和10911端口是否正常,如果正常可以关闭vip通道再次尝试,以JAVA客户端的话就是下面这样<br>
生产者关闭VIP通道:</li>
</ul>
<pre><code>producer.setVipChannelEnabled(false);
</code></pre><p>消费者关闭VIP通道:</p>
<pre><code>consumer.setVipChannelEnabled(false);
</code></pre><p>关闭VIP通道为什么就可以了呢，是因为VIP通道占用了一个端口,10909端口,而服务器的10909端口没有对外开放，所以导致失败了。</p>
<h2 id="配置文件">配置文件</h2>
<p>这是我的<code>broker.properties</code>配置文件</p>
<pre><code>brokerClusterName = DefaultCluster  
brokerName = broker-a  
brokerId = 0  
deleteWhen = 04  
fileReservedTime = 48  
brokerRole = ASYNC_MASTER  
flushDiskType = ASYNC_FLUSH  

brokerIP1=172.17.59.146  
brokerIP2=172.17.59.146  
namesrvAddr=172.17.59.146:5776  
autoCreateTopicEnable=true  
</code></pre><p>因为我没有使用默认的9876端口,所以也有一个name server的配置文件,<code>namesrv.conf</code></p>
<pre><code>listenPort=5776
</code></pre><p>也可以直接下载我的<a href="https://res.cloudinary.com/lyp/raw/upload/v1543502478/hugo/blog.github.io/apache-rocketMQ-introduction/broker.properties">broker.properties</a>和<a href="https://res.cloudinary.com/lyp/raw/upload/v1543502477/hugo/blog.github.io/apache-rocketMQ-introduction/namesrv.conf">namesrv.conf</a></p>
<p>使用自己的配置文件启动name server和broker的时候都是添加一个指定文件的参数<code>-c 文件路径</code></p>
<p>到目前为止，一个简单的apache RocketMQ单机实例已经部署好了，开始愉快的消息队列旅程吧！</p>


        <h2>微信公众号</h2>
<p>扫描下面的二维码关注我们的微信公众号,第一时间查看最新内容。同时也可以关注我的Github，看看我都在了解什么技术，在页面底部可以找到我的Github。</p>
<img src="https://res.cloudinary.com/lyp/image/upload/v1581729955/hugo/blog.github.io/qrcode_for_sikekafeidou.jpg" alt="wechat-account-qrcode">


                <hr>

                <ul class="pager">
                    
                    <li class="previous">
                        <a href="/post/note-ci-repo/" data-toggle="tooltip" data-placement="top" title="CI过程中拉取仓库的注意点">&larr; CI过程中拉取仓库的注意点</a>
                    </li>
                    
                    
                    <li class="next">
                        <a href="/post/sofarpc-design/" data-toggle="tooltip" data-placement="top" title="转|SOFARPC框架之总体设计与扩展机制">转|SOFARPC框架之总体设计与扩展机制 &rarr;</a>
                    </li>
                    
                </ul>

            
<script src="https://utteranc.es/client.js"
repo="liangyuanpeng/liangyuanpeng.github.io"
issue-term="title"
theme="github-light"
crossorigin="anonymous"
async>
</script>



            </div>

            


            
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                sidebar-container">

                
                <section>
                    <hr class="hidden-sm hidden-xs">
                    <h5><a href="/tags/">FEATURED TAGS</a></h5>
                    <div class="tags">
                     
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                            <a href="/tags/blog" title="blog">
                                blog
                            </a>
                        
                    
                        
                    
                        
                            <a href="/tags/chirpstack" title="chirpstack">
                                chirpstack
                            </a>
                        
                    
                        
                    
                        
                            <a href="/tags/ci/cd" title="ci/cd">
                                ci/cd
                            </a>
                        
                    
                        
                    
                        
                            <a href="/tags/cloudnative" title="cloudnative">
                                cloudnative
                            </a>
                        
                    
                        
                            <a href="/tags/cncf" title="cncf">
                                cncf
                            </a>
                        
                    
                        
                    
                        
                            <a href="/tags/docker" title="docker">
                                docker
                            </a>
                        
                    
                        
                            <a href="/tags/docker-compose" title="docker-compose">
                                docker-compose
                            </a>
                        
                    
                        
                    
                        
                    
                        
                    
                        
                            <a href="/tags/fluentd" title="fluentd">
                                fluentd
                            </a>
                        
                    
                        
                    
                        
                    
                        
                            <a href="/tags/halo" title="halo">
                                halo
                            </a>
                        
                    
                        
                            <a href="/tags/hugo" title="hugo">
                                hugo
                            </a>
                        
                    
                        
                            <a href="/tags/image" title="image">
                                image
                            </a>
                        
                    
                        
                    
                        
                            <a href="/tags/iot" title="iot">
                                iot
                            </a>
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                            <a href="/tags/kubernetes" title="kubernetes">
                                kubernetes
                            </a>
                        
                    
                        
                    
                        
                    
                        
                    
                        
                            <a href="/tags/lorawan" title="lorawan">
                                lorawan
                            </a>
                        
                    
                        
                    
                        
                    
                        
                    
                        
                            <a href="/tags/middleware" title="middleware">
                                middleware
                            </a>
                        
                    
                        
                    
                        
                            <a href="/tags/mq" title="mq">
                                mq
                            </a>
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                            <a href="/tags/ops" title="ops">
                                ops
                            </a>
                        
                    
                        
                    
                        
                            <a href="/tags/prometheus" title="prometheus">
                                prometheus
                            </a>
                        
                    
                        
                    
                        
                    
                        
                            <a href="/tags/rpc" title="rpc">
                                rpc
                            </a>
                        
                    
                        
                    
                        
                            <a href="/tags/sofa" title="sofa">
                                sofa
                            </a>
                        
                    
                        
                            <a href="/tags/sofastack" title="sofastack">
                                sofastack
                            </a>
                        
                    
                        
                            <a href="/tags/springboot" title="springboot">
                                springboot
                            </a>
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                    </div>
                </section>



               

                
                
            </div>

            
            
            <div class="
            col-lg- col-lg-offset-2
            col-md-10 col-md-offset-1
            ">
            <section>
                <hr class="hidden-sm hidden-xs">
                

            </section>
            </div>
            


        </div>
    </div>
</article>






<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                   
                    
                    <li>
                        <a target="_blank" href="https://github.com/liangyuanpeng">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                   
                    
                    <li>
                        <a href="mailto:liangyuanpengem@163.com">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-envelope fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
		    

                    
                    <li>
                        <a href="https://twitter.com/lan31793328">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                    
                    
                    <li>
                        <a target="_blank" href="https://www.zhihu.com/people/liangyuanpeng">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa  fa-stack-1x fa-inverse">知</i>
                            </span>
                        </a>
                    </li>
		    
                    
                    <li>
                        <a target="_blank" href="https://weibo.com/u/1908782280">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-weibo fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
		    

                    

		    
                    
                    
                </ul>
		<p class="copyright text-muted">
                    Copyright &copy; Hi,I`m lan , 2018
                    <br>
                    <a href="https://themes.gohugo.io/hugo-theme-cleanwhite">CleanWhite Hugo Theme</a> by <a href="https://zhaohuabing.com">Huabing</a> |
                    <iframe
                        style="margin-left: 2px; margin-bottom:-5px;"
                        frameborder="0" scrolling="0" width="100px" height="20px"
                        src="https://ghbtns.com/github-btn.html?user=zhaohuabing&repo=hugo-theme-cleanwhite&type=star&count=true" >
                    </iframe>
                </p>
            </div>
        </div>
    </div>
</footer>




<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>






<script>
    
    if($('#tag_cloud').length !== 0){
        async("/js/jquery.tagcloud.js",function(){
            $.fn.tagcloud.defaults = {
                
                color: {start: '#bbbbee', end: '#0085a1'},
            };
            $('#tag_cloud a').tagcloud();
        })
    }
</script>


<script>
    async("https://cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.js", function(){
        var $nav = document.querySelector("nav");
        if($nav) FastClick.attach($nav);
    })
</script>







<script>
    
    var _baId = 'fad9c137f8ce239f9b323d36c871f8e6';

    
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?" + _baId;
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
</script>







</body>
</html>
